package com.guragura.widget;

import java.util.List;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;


/**
 * @author hartono
 * buat animated sprite
 */
public class AnimatedSprite extends Sprite{
	
	private Animation loadingAnimation;
	private float stateTime = 0;
	private List<TextureAtlas.AtlasRegion> regions;	
	
	public AnimatedSprite(List<TextureAtlas.AtlasRegion> regions) {
		// TODO Auto-generated constructor stub
		super(regions.get(0));
		this.regions= regions;
		loadingAnimation = new Animation(0.25f, regions);
	}

	@Override
	public void draw(SpriteBatch spriteBatch) {
		// TODO Auto-generated method stub
		super.draw(spriteBatch);
		TextureRegion region = loadingAnimation.getKeyFrame(stateTime, true);		
		setRegion(region);
		stateTime += Gdx.graphics.getDeltaTime();
	}
}
